﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

namespace IntegratedOnBordDebug.UDPCore
{
    public class SEAESendPool
    {
        private bool _isOnAction = true;
        /// <summary>实例是否在使用标志 fase 可用、true 在用
        /// 
        /// </summary>
        public bool IsOnAction { get { return _isOnAction; } set { _isOnAction = value; } }

        private SocketAsyncEventArgs _saea;

        /// <summary>发送用的IO完成端口参数对象
        /// 
        /// </summary>
        public SocketAsyncEventArgs SAEA {
            get { return _saea; }
            set { _saea = value; }
        }

        //public SEAESendPool() {
        //    _saea = new SocketAsyncEventArgs();
        //    _saea.Completed += new EventHandler<SocketAsyncEventArgs>(IOComplete);       
        //}

        private void IOComplete(object sender, SocketAsyncEventArgs e)
        {
            switch (e.LastOperation)
            {
                case SocketAsyncOperation.Send:
                    if (e.SocketError == SocketError.Success)
                    {
                        
                    }
                        _isOnAction = true;
                    break;
                default:
                    throw new ArgumentException("The last operation completed on the socket was not a receive or send");
            }
        }

        public SEAESendPool(Socket TargetSocket)
        {
            _saea = new SocketAsyncEventArgs();
            _saea.AcceptSocket = TargetSocket;
            _saea.UserToken = TargetSocket;
            _saea.Completed += new EventHandler<SocketAsyncEventArgs>(IOComplete);

        }
    }
}
